const getMonthDate = function (year, month) {
  month = parseInt(month, 10);
  var date = new Date(year, month, 0);
  return date.getDate();
};
//创建时间轴
function createTimeNode(id, text, x, y, width, height, fill) {
  return {
    id,
    x,
    y,
    width,
    height,
    attrs: {
      body: {
        fill: fill || "blue",
        stroke: "black",
      },
      label: {
        text: text,
        fill: "black",
        fontSize: 12,
      },
    },
    isDate: true,
  };
}
function createTimeLine(graph) {
  let num = 0;
  for (let i = 2021; i <= 2022; i++) {
    for (let j = 1; j <= 12; j++) {
      if (j < 10) j = `0${j}`;
      const monthDate = getMonthDate(i, j);
      for (let k = 1; k <= monthDate; k++) {
        if (k < 10) k = `0${k}`;
        graph.addNode(
          createTimeNode(
            `${i}-${j}-${k}`,
            k,
            num++ * 20 * 2,
            20,
            20 * 2,
            20 * 2,
            "white"
          )
        );
      }
      graph.addNode(
        createTimeNode(
          `${i}-${j}`,
          `${i}-${j}`,
          2 * 20 * (num - monthDate),
          0,
          monthDate * 20 * 2,
          20,
          "white"
        )
      );
    }
  }
}
export { getMonthDate, createTimeLine };
